package cn.edu.ccut.refactor;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.ltk.core.refactoring.participants.RefactoringProcessor;
import org.eclipse.ltk.core.refactoring.participants.RenameRefactoring;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.*;

/**
 * 
 * @author Bai Yucheng 2008-1-8
 * 
 */
public class RenameInputWizardPage extends TextInputWizardPage {
	public static boolean flag = false;
	public RenameInputWizardPage(String s, boolean flag) {
		super(s, flag);
	}

	public RenameInputWizardPage(String s, boolean flag, String s1) {
		super(s, flag, s1);
	}

	public void createControl(Composite composite) {
		Composite composite1 = new Composite(composite, 0);
		setControl(composite1);
		initializeDialogUnits(composite1);
		composite1.setLayout(new GridLayout());
		Composite composite2 = new Composite(composite1, 0);
		composite2.setLayoutData(new GridData(768));
		GridLayout gridlayout = new GridLayout();
		gridlayout.numColumns = 2;
		composite2.setLayout(gridlayout);
		Label label = new Label(composite2, 0);
		label.setText(Messages.getString("RenameInputWizardPage.0"));  //$NON-NLS-1$
		Text text = createTextInputField(composite2);
		RenameRefactoring renamerefactoring = (RenameRefactoring) getRefactoring();
		RefactoringProcessor refactoringprocessor = renamerefactoring.getProcessor();
		text.setLayoutData(new GridData(768));
		text.selectAll();
		final Button button = new Button(composite1, 32);
		button.setText(Messages.getString("RenameInputWizardPage.1"));  //$NON-NLS-1$
		button.setSelection(true);
		((AbstractRenameProcessor) refactoringprocessor).setUpdateReference(button.getSelection());
		button.addSelectionListener(new SelectionAdapter() {

			public void widgetSelected(SelectionEvent selectionevent) {
				handleReference(button.getSelection());
			}

		});
		Dialog.applyDialogFont(composite1);
	}

	private void handleReference(boolean flag) {
		RenameRefactoring renamerefactoring = (RenameRefactoring) getRefactoring();
		RefactoringProcessor refactoringprocessor = renamerefactoring.getProcessor();
		((AbstractRenameProcessor) refactoringprocessor).setUpdateReference(flag);
	}

//	public void setVisible(boolean visible) {
//		flag = !visible;
//		super.setVisible(visible);
//	}
}